<template>
  <div class="content-block">
    <div class="info-head">{{ title }}</div>
    <div class="info-content padding" style="padding-top: 20px;">
      <div class="flex justify-between overview">
        <div
          class="overview-item" v-for="(item, index) in info"
          :key="index" :style="{backgroundColor: themeColor}"
        >
      <span class="item-icon" v-if="item.icon">
        <svg-icon :name="item.icon"></svg-icon>
      </span>
          <h2 class="item-label">{{ item.label }}</h2>
          <div class="item-main">
            <span class="item-number">{{ item.count }}</span>
            <span class="item-unit">{{ item.unit }}</span>
          </div>
          <p class="item-content">
            {{ item.content }}
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'grid-item-one',
  props: {
    title: String,
  },
  computed: {
    themeColor () {
      return this.$store.state.user.theme
    },
    energyVariety () {
      return this.$store.state.energyVariety
    },
    energyUnits () {
      return this.$store.state.energyUnits
    },
    info () {
      const rand = (n = 100) => (Math.random() * n).toFixed(2)
      return this.energyVariety.map(v => ({
        label: v.name,
        count: rand(10000),
        unit: this.getUnit(v.value),
        content: '同比：' + rand(10) + '%'
      }))
    },
  },
  mounted () {
    this.$store.dispatch('GET_ENERGY_VARIETY')
  },
  methods: {
    getUnit (key) {
      const energyUnits = this.energyUnits
      const target = energyUnits.find(v => v.key === key)
      return target ? target.value : ''
    }
  },
}
</script>


<style lang="scss" scoped>
@import "@/assets/style/variable.scss";

.overview-item {
  flex: 1;
  border-radius: 4px;
  padding: 30px 20px;
  color: white;
  position: relative;
  overflow: hidden;

  & + .overview-item {
    margin-left: $gutter;
  }
}

.item-label {
  font-size: 22px;
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 2rem;
}

.item-number {
  font-size: 20px;
  color: orange;
  margin-right: 5px;
}

.item-icon {
  position: absolute;
  right: 20px;
  bottom: 10px;
  font-size: 3vw;
  color: white;
  opacity: .8;
}
</style>
